package com.dean.service;

import com.dean.dao.DeanToolDao;
import com.dean.entity.SysDbConnInfo;
import com.dean.utils.DeanJdbcUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @ClassName DbConnService
 * @Description db 连接配置处理
 * @Author dean
 * @Date 2021/12/27 15:19
 */
public class DbConnService {
    private static final Logger logger = LoggerFactory.getLogger(DbConnService.class);

    private DbConnService(){
    }
    private static volatile DbConnService INSTANCE;
    public static DbConnService getInstance(){
        if(INSTANCE == null){
            synchronized (DbQueryService.class){
                if(INSTANCE == null){
                    INSTANCE = new DbConnService();
                }
            }
        }
        return INSTANCE;
    }

    public List<SysDbConnInfo> getConnInfos(){
        List<SysDbConnInfo> results = DeanToolDao.getInstance().queryConnInfo();
        return results;
    }

    public SysDbConnInfo getConnInfo(String connName){
        SysDbConnInfo results = DeanToolDao.getInstance().queryConnInfo(connName);
        return results;
    }

    public boolean save(SysDbConnInfo connInfo){
        DeanToolDao.getInstance().delConnInfo(connInfo.getConnName());
        return DeanToolDao.getInstance().saveConnInfo(connInfo);
    }

    public boolean del(String connName){
        return DeanToolDao.getInstance().delConnInfo(connName);
    }


}
